package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoopihgCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {

    @Resource
    private ShoopihgCartService shoopihgCartService;

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车...");
        shoopihgCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     */
    @RequestMapping("/list")
    public Result<Object> list(){
        log.info("查看购物车...");
        return Result.success(shoopihgCartService.list());
    }

    /**
     * 清空购物车
     */
    @DeleteMapping("/clean")
    public Result clean(){
        log.info("清空购物车...");
        shoopihgCartService.clean();
        return Result.success();
    }

    /**
     * 删除购物车中一个商品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中一个商品...");
        shoopihgCartService.sub(shoppingCartDTO);
        return Result.success();
    }
}
